/**
 * 
 */
package GUI.main.navigation;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import GUI.helpers.ButtonType;
import GUI.helpers.PButton;
import GUI.main.MainClient;
import GUI.main.dialogs.PatientAppointmentsDialog;

/**
 * patient specific nav panel to be placed in nav panel.
 * 
 * @author mramsey3
 * 
 */
public class PatientNavigationMenuPanel extends JPanel implements
	ActionListener {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private JPanel buttonPanel;
    private JPanel viewHistoryPanel;
    private PButton viewHistory;
    private JPanel logoutPanel;
    private PButton logoutButton;

    /**
     * 
     */
    public PatientNavigationMenuPanel() {
	super();
	setLayout(new BorderLayout());
	setPreferredSize(new Dimension(200, 450));
	add(getButtonPanel(), BorderLayout.CENTER);
    }

    /**
     * @return
     */
    private JPanel getButtonPanel() {
	if (buttonPanel == null) {
	    buttonPanel = new JPanel();
	    buttonPanel.setBorder(new EmptyBorder(10,10,10,10));
	    buttonPanel.setLayout(new BoxLayout(buttonPanel,
		    BoxLayout.PAGE_AXIS));
	    buttonPanel.add(Box.createVerticalStrut(200));
	    buttonPanel.add(getViewHistoryPanel());
	    buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
	    buttonPanel.add(getLogoutPanel());
	    buttonPanel.add(Box.createVerticalStrut(200));
	}
	return buttonPanel;
    }

    /**
     * @return
     */
    private JPanel getViewHistoryPanel() {
	if (viewHistoryPanel == null) {
	    viewHistoryPanel = new JPanel();
	    viewHistoryPanel.add(getViewHistory());
	}
	return viewHistoryPanel;
    }

    /**
     * @author mramsey3
     * @return
     */
    private PButton getViewHistory() {
	if (viewHistory == null) {
	    viewHistory = new PButton("View History",ButtonType.LONG);
	    viewHistory.addActionListener(this);
	}
	return viewHistory;
    }

    /**
     * @return
     */
    private JPanel getLogoutPanel() {
	if (logoutPanel == null) {
	    logoutPanel = new JPanel();
	    logoutPanel.add(getLogoutButton());
	}
	return logoutPanel;
    }

    /**
     * @return
     */
    private PButton getLogoutButton() {
	if (logoutButton == null) {
	    logoutButton = new PButton("Logout",ButtonType.LONG);
	    logoutButton.addActionListener(this);
	}
	return logoutButton;
    }

    /**
     * @author mramsey3
     * @param viewHistory
     */

    @Override
    public void actionPerformed(ActionEvent e) {
	if (e.getSource() == viewHistory) {
	    PatientAppointmentsDialog temp = new PatientAppointmentsDialog();
	    temp.setVisible(true);
	} else if (e.getSource() == logoutButton) {
	    MainClient.logOut();
	}
    }

}
